package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="attachment")
@Searchable
@XmlRootElement
public class Attachment extends BaseObject implements Serializable {
    private Long id;
    private String name;
    private String path;
    private Date uploadTime;
    private Long uploadUser;
    private Long size;
    private String type;
    private Long ownerId;
    private Long ownerType;

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="name", nullable=false, length=256)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="path", nullable=false, length=1024)
    @SearchableProperty
    public String getPath() {
        return this.path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="upload_time", nullable=false, length=19)
    @SearchableProperty
    public Date getUploadTime() {
        return this.uploadTime;
    }
    
    public void setUploadTime(Date uploadTime) {
        this.uploadTime = uploadTime;
    }
    
    @Column(name="upload_user", nullable=false)
    @SearchableProperty
    public Long getUploadUser() {
        return this.uploadUser;
    }
    
    public void setUploadUser(Long uploadUser) {
        this.uploadUser = uploadUser;
    }
    
    @Column(name="size", nullable=false)
    @SearchableProperty
    public Long getSize() {
        return this.size;
    }
    
    public void setSize(Long size) {
        this.size = size;
    }
    
    @Column(name="type", nullable=false, length=16)
    @SearchableProperty
    public String getType() {
        return this.type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
    @Column(name="owner_id", nullable=false)
    @SearchableProperty
    public Long getOwnerId() {
        return this.ownerId;
    }
    
    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }
    
    @Column(name="owner_type", nullable=false)
    @SearchableProperty
    public Long getOwnerType() {
        return this.ownerType;
    }
    
    public void setOwnerType(Long ownerType) {
        this.ownerType = ownerType;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Attachment pojo = (Attachment) o;

        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (path != null ? !path.equals(pojo.path) : pojo.path != null) return false;
        if (uploadTime != null ? !uploadTime.equals(pojo.uploadTime) : pojo.uploadTime != null) return false;
        if (uploadUser != null ? !uploadUser.equals(pojo.uploadUser) : pojo.uploadUser != null) return false;
        if (size != null ? !size.equals(pojo.size) : pojo.size != null) return false;
        if (type != null ? !type.equals(pojo.type) : pojo.type != null) return false;
        if (ownerId != null ? !ownerId.equals(pojo.ownerId) : pojo.ownerId != null) return false;
        if (ownerType != null ? !ownerType.equals(pojo.ownerType) : pojo.ownerType != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (name != null ? name.hashCode() : 0);
        result = 31 * result + (path != null ? path.hashCode() : 0);
        result = 31 * result + (uploadTime != null ? uploadTime.hashCode() : 0);
        result = 31 * result + (uploadUser != null ? uploadUser.hashCode() : 0);
        result = 31 * result + (size != null ? size.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (ownerId != null ? ownerId.hashCode() : 0);
        result = 31 * result + (ownerType != null ? ownerType.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("path").append("='").append(getPath()).append("', ");
        sb.append("uploadTime").append("='").append(getUploadTime()).append("', ");
        sb.append("uploadUser").append("='").append(getUploadUser()).append("', ");
        sb.append("size").append("='").append(getSize()).append("', ");
        sb.append("type").append("='").append(getType()).append("', ");
        sb.append("ownerId").append("='").append(getOwnerId()).append("', ");
        sb.append("ownerType").append("='").append(getOwnerType()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
